package com.feng.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.feng.entity.CarItem;
import com.feng.entity.User;
import com.feng.service.ServletOrder;
import com.feng.util.web.ServletUtil;

public class order extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/*User user = (User) request.getSession().getAttribute("user");
		if(user == null) {
			ServletUtil.redirect(response, "userLogin.jspx?to=order.jspx");
			return;
		}*/
		ServletUtil.forword(request, response, "order");
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		User u = (User) ServletUtil.getSession(request).getAttribute("user");
		if(u!=null){
			String name = request.getParameter("name");
			String tel = request.getParameter("tel");
			String address = request.getParameter("address");
			String content = request.getParameter("content");
			String paytype = request.getParameter("paytype");
			
			List<CarItem> list = (List<CarItem>)request.getSession().getAttribute("shopcar");
			new ServletOrder().save(u,name,tel,address,content,paytype,list);
			ServletUtil.getSession(request).removeAttribute("shopcar");
			ServletUtil.forword(request, response, "order-success");
		}
	}

}
